package tech.aistar.corejava.day10.dat10work.Test10;

/**
 * Created by 豆梦寒 on 2019/7/27.
 */
public class MaxSubStr {
    public static String getMaxSubString(String str1, String str2) {
        String sameStr = "";
        for (int index = 0; index < str2.length(); index++) {
            for (int j = 0; j < str2.length() - index; j++) {
                String substr = str2.substring(index, str2.length() - j);
                if (-1 != str1.indexOf(substr))
                    if (sameStr.length() <= substr.length()) {
                        sameStr = substr;
                    }
            }
        }
        return !sameStr.equals("") ? sameStr : "Have no same sub string";
    }
    public static void main(String[] args) {
        String str1 = "adbccadebbca";
        String str2 = "edabccadece";
        String str3 = "adbccadebbcaaaaaa";
        String str4 = "edabccadeceaaaaaa";
        System.out.println("最大公串是:  " + getMaxSubString(str1, str2));
        System.out.println("最大公串是:  " + getMaxSubString(str3, str4));
    }
}
